﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_receive
	/// </summary>
	public partial class enterprise_receive
	{
		public enterprise_receive()
		{}

        /// <summary>
        /// 分页获取应聘职位简历信息列表
        /// </summary>
        /// <param name="enterprise_bid">企业ID</param>
        /// <param name="currentPageIndex">当前页</param>
        /// <param name="pageSize">每页显示条目数</param>
        /// <param name="count">总条目数</param>
        /// <returns>返回的DataSet第2个表是企业名称</returns>
        public DataSet GetReceive(int enterprise_bid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@enterprise_bid",SqlDbType.Int),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int)
            };

            para[0].Value = enterprise_bid;
            para[1].Value = currentPageIndex;
            para[2].Value = pageSize;
            para[3].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperSQL.RunProcedure("P_Get_enterprise_receive", para, "ds");

            count = Convert.ToInt32(para[3].Value);


            return ds;
        }


        /// <summary>
        ///  更新阅读状态为true
        /// </summary>
        public bool UpdateIsbrowse(int enterprise_receive_id)
        {
            int rowsAffected = 0;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_receive_id", SqlDbType.Int,4)};
            parameters[0].Value = enterprise_receive_id;

            rowsAffected = DbHelperSQL.ExecuteSql(" update enterprise_receive set isbrowse=1 where enterprise_receive_id=@enterprise_receive_id ", parameters);
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
      
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_receive_id", "enterprise_receive"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_receive_id)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_receive_id", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_receive_id;

			int result= DbHelperSQL.RunProcedure("enterprise_receive_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.enterprise_receive model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_receive_id", SqlDbType.Int,4),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@receivetime", SqlDbType.DateTime),
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4),
					new SqlParameter("@isbrowse", SqlDbType.Bit,1)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.uid;
			parameters[2].Value = model.receivetime;
			parameters[3].Value = model.enterprise_rid;
			parameters[4].Value = model.isbrowse;

			DbHelperSQL.RunProcedure("enterprise_receive_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_receive model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_receive_id", SqlDbType.Int,4),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@receivetime", SqlDbType.DateTime),
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4),
					new SqlParameter("@isbrowse", SqlDbType.Bit,1)};
			parameters[0].Value = model.enterprise_receive_id;
			parameters[1].Value = model.uid;
			parameters[2].Value = model.receivetime;
			parameters[3].Value = model.enterprise_rid;
			parameters[4].Value = model.isbrowse;

			DbHelperSQL.RunProcedure("enterprise_receive_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_receive_id)
		{
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from enterprise_receive ");
            strSql.Append(" where enterprise_receive_id=@enterprise_receive_id");

            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_receive_id", SqlDbType.Int,4)
};
            parameters[0].Value = enterprise_receive_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_receive_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from enterprise_receive ");
			strSql.Append(" where enterprise_receive_id in ("+enterprise_receive_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.enterprise_receive GetModel(int enterprise_receive_id)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_receive_id", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_receive_id;

			lcmyjobs.Model.enterprise_receive model=new lcmyjobs.Model.enterprise_receive();
			DataSet ds= DbHelperSQL.RunProcedure("enterprise_receive_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["enterprise_receive_id"]!=null && ds.Tables[0].Rows[0]["enterprise_receive_id"].ToString()!="")
				{
					model.enterprise_receive_id=int.Parse(ds.Tables[0].Rows[0]["enterprise_receive_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["uid"]!=null && ds.Tables[0].Rows[0]["uid"].ToString()!="")
				{
					model.uid=int.Parse(ds.Tables[0].Rows[0]["uid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["receivetime"]!=null && ds.Tables[0].Rows[0]["receivetime"].ToString()!="")
				{
					model.receivetime=DateTime.Parse(ds.Tables[0].Rows[0]["receivetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["enterprise_rid"]!=null && ds.Tables[0].Rows[0]["enterprise_rid"].ToString()!="")
				{
					model.enterprise_rid=int.Parse(ds.Tables[0].Rows[0]["enterprise_rid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["isbrowse"]!=null && ds.Tables[0].Rows[0]["isbrowse"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["isbrowse"].ToString()=="1")||(ds.Tables[0].Rows[0]["isbrowse"].ToString().ToLower()=="true"))
					{
						model.isbrowse=true;
					}
					else
					{
						model.isbrowse=false;
					}
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_receive_id,uid,receivetime,enterprise_rid,isbrowse ");
			strSql.Append(" FROM enterprise_receive ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_receive_id,uid,receivetime,enterprise_rid,isbrowse ");
			strSql.Append(" FROM enterprise_receive ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_receive";
			parameters[1].Value = "enterprise_receive_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

